package org.x4444.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "Z_ORDER")
public class Order implements Serializable {

	private static final long serialVersionUID = -6762734583449836012L;

	Integer id;

	Client client;

	Date orderDate;

	Collection<OrderDetail> orderDetail;

	public Order() {
		// TODO Auto-generated constructor stub
	}

	@Id
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name = "CLIENT_ID", referencedColumnName = "ID")
	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "ORDER_DATE")
	public Date getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}

	@OneToMany(targetEntity = OrderDetail.class, mappedBy = "order")
	public Collection<OrderDetail> getOrderDetail() {
		return orderDetail;
	}

	public void setOrderDetail(Collection<OrderDetail> orderDetail) {
		this.orderDetail = orderDetail;
	}

	@Override
	public String toString() {
		return "" + id + " " + client.toString() + " " + orderDate;
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return 7 + 31 * id;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof Order)) {
			return false;
		}

		Order o2 = (Order) obj;
		if (id != null) {
			return id == o2.id;
		}
		return false;
	}
}
